@extends('shop::layouts.master')
@section('title')
    {{$title}}
@endsection

<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<style>
    .el-upload-list--text{
        height:30px;
    }
</style>

@section('tab')

    <form class="layui-form">
        <div class="goods_fax">
            <div class="layui-row">
                <div class="layui-tab layui-tab-brief" lay-filter="form_add">
                    <div class="layui-tab-content">
                        <input type="hidden" name="id" value="">

                        <div class="layui-form-item">
                            <label class="layui-form-label">版本</label>
                            <div class="layui-input-inline">
                                <input type="text" name="edition" maxlength="10" value="" lay-verify="required" autocomplete="off"  class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">版本号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="version" value="" maxlength="10" lay-verify="required" autocomplete="off"  class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">
                                <span class="x-red">*</span>version code 安卓版本号为数字
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">类型</label>
                            <div class="layui-input-inline">
                                <select name="type" lay-filter="form_type">
                                    @foreach($arr_app_type as $key=>$value)
                                        <option value="{{$key}}">{{$value}}</option>
                                    @endforeach
                                </select>
                            </div>

                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">是否强制更新</label>
                            <div class="layui-input-inline">
                                <select name="is_force" lay-filter="form_is_force">
                                    @foreach($arr_is_force as $key=>$value)
                                        <option value="{{$key}}">{{$value}}</option>
                                    @endforeach
                                </select>
                            </div>

                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">安装包</label>
                            <div class="layui-input-inline">
                                <input type="hidden" id="input_url" name="url" value="">

                                <div id="app">

                                    <el-upload
                                            class="upload-demo"
                                            action="http://xd-admin.rome88.com/admin-element_upload_file?size=100"
                                            {{--            accept="video/avi,video/rmvb,video/rm,video/mp4,video/3gp"--}}
                                            :on-preview="handlePreview"
                                            :on-success="handleSuccess"
                                            :on-remove="handleRemove"
                                            :before-remove="beforeRemove"
                                            :limit="1"
                                            :on-exceed="handleExceed"
                                            :file-list="fileList">
                                        <el-button size="small" type="primary">点击上传</el-button>
                                    </el-upload>
                                </div>

                            </div>
                            <div class="layui-form-mid layui-word-aux">
                                <span class="x-red">*</span>文件大小不能超过100M
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">版本更新说明</label>
                            <div class="layui-input-inline">
                                <textarea lay-verify="required" name="content" maxlength="200" cols="50" rows="5"></textarea>

                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label for="L_repass" class="layui-form-label"></label>
                            <button class="layui-btn" lay-filter="add" lay-submit="">提交</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </form>
    <!-- import Vue before Element -->
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <!-- import JavaScript -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script>
        new Vue({
            el: '#app',
            data() {
                return {
                    fileList: []
                };
            },
            methods: {
                handleSuccess(response, file, fileList) {
                    if(response.state != 0){
                        this.fileList = [];
                    }
                    else {
                        var input_url = $('#input_url');
                        var oss_file_full_name =  response.data.url;
                        input_url.val(oss_file_full_name);
                    }

                    // console.log(response);
                    // console.log(response, file, fileList);
                },
                handleRemove(file, fileList) {
                    var input_url = $('#input_url');
                    var oss_file_full_name =  '';
                    input_url.val(oss_file_full_name);
                    // console.log(file, fileList);
                },
                handlePreview(file) {
                    // console.log(file);
                },
                handleExceed(files, fileList) {
                    this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
                },
                beforeRemove(file, fileList) {
                    return this.$confirm(`确定移除 ${ file.name }？`);
                }
            }
        })

    </script>
@endsection

@section('tab_js')
    <script>
        layui.use(['form', 'layer', 'jquery','upload'], function () {
            $ = layui.jquery;
            var form = layui.form,
                upload = layui.upload,
                layer = layui.layer;
            //监听提交
            form.on('submit(add)', function (data) {

                var form_data = data.field;
                if(form_data.url.length <= 0){
                    layer.msg('请上传安装包');
                    return  false;
                }

                $.ajax({
                    url: js_url('admin_app_app_add_do'),
                    type: 'post',
                    data: data.field,
                    dataType: "json",
                    success: function (result) {
                        if (result.state === 0) {
                            layer.msg(result.msg, {time: 600, icon: 6}, function () {
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                        } else {
                            layer.msg(result.msg, {time: 600, icon: 5});
                        }
                    }
                });
                return false;
            });


        });
    </script>
@endsection


